/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CreateNewEmployeeDlg.java
 *
 * Created on 2011-11-3, 1:53:01
 */
package view.admin;

import business.CreateNewEmpCmd;
import javax.swing.JOptionPane;
import model.Employee;
import model.EmployeeFactory;
import model.EmployeeFactory.EmployeeClass;

/**
 *
 * @author Administrator
 */
public class CreateNewEmployeeDlg extends javax.swing.JDialog {

    /** Creates new form CreateNewEmployeeDlg */
    public CreateNewEmployeeDlg(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sexGroup = new javax.swing.ButtonGroup();
        roleGroup = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        nameField = new javax.swing.JTextField();
        idField = new javax.swing.JTextField();
        passwordField = new javax.swing.JPasswordField();
        confirmBtn = new javax.swing.JButton();
        cancelBtn = new javax.swing.JButton();
        frontOperatorBtn = new javax.swing.JRadioButton();
        departManagerBtn = new javax.swing.JRadioButton();
        busiManangerBtn = new javax.swing.JRadioButton();
        adminBtn = new javax.swing.JRadioButton();
        male = new javax.swing.JRadioButton();
        female = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("姓名");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText("性别");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText("身份证");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText("密码");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText("权限");
        jLabel5.setName("jLabel5"); // NOI18N

        nameField.setName("nameField"); // NOI18N

        idField.setName("idField"); // NOI18N

        passwordField.setName("passwordField"); // NOI18N

        confirmBtn.setText("确定");
        confirmBtn.setName("confirmBtn"); // NOI18N
        confirmBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmBtnActionPerformed(evt);
            }
        });

        cancelBtn.setText("取消");
        cancelBtn.setName("cancelBtn"); // NOI18N
        cancelBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelBtnActionPerformed(evt);
            }
        });

        roleGroup.add(frontOperatorBtn);
        frontOperatorBtn.setSelected(true);
        frontOperatorBtn.setText("前台操作员");
        frontOperatorBtn.setName("frontOperatorBtn"); // NOI18N

        roleGroup.add(departManagerBtn);
        departManagerBtn.setText("银行经理");
        departManagerBtn.setName("departManagerBtn"); // NOI18N

        roleGroup.add(busiManangerBtn);
        busiManangerBtn.setText("业务总管");
        busiManangerBtn.setName("busiManangerBtn"); // NOI18N

        roleGroup.add(adminBtn);
        adminBtn.setText("系统管理员");
        adminBtn.setName("adminBtn"); // NOI18N

        sexGroup.add(male);
        male.setSelected(true);
        male.setText("男");
        male.setName("male"); // NOI18N

        sexGroup.add(female);
        female.setText("女");
        female.setName("female"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(idField)
                            .addComponent(nameField, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(frontOperatorBtn)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(departManagerBtn)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(busiManangerBtn))
                            .addComponent(adminBtn)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(male)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(female))
                            .addComponent(passwordField)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(confirmBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(63, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(27, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(male)
                    .addComponent(female))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(idField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(frontOperatorBtn)
                            .addComponent(departManagerBtn)
                            .addComponent(busiManangerBtn))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(adminBtn)
                        .addGap(47, 47, 47))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(confirmBtn)
                        .addComponent(cancelBtn)))
                .addGap(15, 15, 15))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_cancelBtnActionPerformed

    private void confirmBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmBtnActionPerformed
        Employee employee = null;
        EmployeeClass ec = null;
        if(frontOperatorBtn.isSelected())
            ec = EmployeeClass.FRONT_OPERATOR;
        else if(departManagerBtn.isSelected())
            ec = EmployeeClass.DEPARTMENT_MANAGER;
        else if(busiManangerBtn.isSelected())
            ec = EmployeeClass.BUSINESS_MANAGER;
        else if(adminBtn.isSelected())
            ec = EmployeeClass.ADMIN;
        EmployeeFactory ef = new EmployeeFactory();
        employee = ef.generateEmployee(ec);
        employee.setId(idField.getText());
        employee.setMale(male.isSelected());
        employee.setName(nameField.getText());
        employee.setPwd(new String(passwordField.getPassword()));
        employee.setRole(ec.toString());
        
        CreateNewEmpCmd cmd = new CreateNewEmpCmd();
        cmd.setEmployee(employee);
        if( cmd.execute(null) ) {
            this.setVisible(false);
            this.dispose();
        }else{
            JOptionPane.showMessageDialog(this, "创建新员工失败 ", "错误", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_confirmBtnActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CreateNewEmployeeDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CreateNewEmployeeDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CreateNewEmployeeDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CreateNewEmployeeDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                CreateNewEmployeeDlg dialog = new CreateNewEmployeeDlg(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton adminBtn;
    private javax.swing.JRadioButton busiManangerBtn;
    private javax.swing.JButton cancelBtn;
    private javax.swing.JButton confirmBtn;
    private javax.swing.JRadioButton departManagerBtn;
    private javax.swing.JRadioButton female;
    private javax.swing.JRadioButton frontOperatorBtn;
    private javax.swing.JTextField idField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JRadioButton male;
    private javax.swing.JTextField nameField;
    private javax.swing.JPasswordField passwordField;
    private javax.swing.ButtonGroup roleGroup;
    private javax.swing.ButtonGroup sexGroup;
    // End of variables declaration//GEN-END:variables
}
